/**
 * Created by gongxun on 17/8/11.
 */


var PdkPlayEffectLayer = cc.Layer.extend({
    ctor : function() {
        this._super();
    },

    onEnter : function(){
        this._super();

        //飞机
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/fei-feiji.plist", "res/effect/pdk/fei-feiji.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/fei-feiji.xml");

        //炸弹
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/zha-zhadan.plist", "res/effect/pdk/zha-zhadan.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/zha-zhadan.xml");

        //顺子
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/shun-shunzi.plist", "res/effect/pdk/shun-shunzi.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/shun-shunzi.xml");

        //连对
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/lian-liandui.plist", "res/effect/pdk/lian-liandui.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/lian-liandui.xml");

        //三顺
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/sanshun.plist", "res/effect/pdk/sanshun.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/sanshun.xml");

        //保单
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/baodan.plist", "res/effect/pdk/baodan.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/baodan.xml");

        //赢了
        cc.spriteFrameCache.addSpriteFrames("res/effect/pdk/woyingle.plist", "res/effect/pdk/woyingle.png");
        ccs.armatureDataManager.addArmatureFileInfo("res/effect/pdk/woyingle.xml");
    },

    playPdkEffect : function(cardType, pos){
        cc.log("effect cardtype:" + cardType);

        if (cardType == CardType.bomb){

            var anim = new ccs.Armature("zd");
            anim.setScale(0.6);
            anim.animation.setSpeedScale(1);
            anim.setPosition(pos);
            this.addChild(anim);
            var that = this;
            anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
                cc.log("movementType:" + movementType);
                if (movementType == 1){
                    armature.scheduleOnce(function(dt){
                        that.removeChild(armature);
                    }, 0.5);
                }
            });

            anim.animation.play("ZD_2", 2, 0);
        }else if (cardType == CardType.straight){

            var anim = new ccs.Armature("yuanjian/shunzis_all");
            anim.setScale(0.6);
            anim.animation.setSpeedScale(1);
            anim.setPosition(pos);
            this.addChild(anim);
            var that = this;
            anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
                cc.log("movementType:" + movementType);
                if (movementType == 1){
                    armature.scheduleOnce(function(dt){
                        that.removeChild(armature);
                    }, 1);
                }
            });

            anim.animation.play("shunzi", 2, 0);
        }else if (cardType == CardType.airplaneSingle || cardType == CardType.airplanePair || cardType == CardType.airplaneEx){

            var anim = new ccs.Armature("fly_all");
            anim.setScale(0.6);
            anim.animation.setSpeedScale(1);
            anim.setPosition(pos);
            this.addChild(anim);
            var that = this;
            anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
                cc.log("movementType:" + movementType);
                if (movementType == 1){
                    armature.scheduleOnce(function(dt){
                        that.removeChild(armature);
                    }, 1);
                }
            });

            anim.animation.play("plane", 2, 0);
        }else if (cardType == CardType.straightPair){

            var anim = new ccs.Armature("liandui_all");
            anim.setScale(0.6);
            anim.animation.setSpeedScale(1);
            anim.setPosition(pos);
            this.addChild(anim);
            var that = this;
            anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
                cc.log("movementType:" + movementType);
                if (movementType == 1){
                    armature.scheduleOnce(function(dt){
                        that.removeChild(armature);
                    }, 1);
                }
            });

            anim.animation.play("liandui", 2, 0);
        }else if (cardType == CardType.straightTriple){

            var anim = new ccs.Armature("sanshun");
            anim.setScale(1);
            anim.animation.setSpeedScale(1);
            anim.setPosition(pos);
            this.addChild(anim);
            var that = this;
            anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
                cc.log("movementType:" + movementType);
                if (movementType == 1){
                    armature.scheduleOnce(function(dt){
                        that.removeChild(armature);
                    }, 0.5);
                }
            });

            anim.animation.play("sanshun", 2, 0);
        }
    },

    //播放保单
    playBaodan : function(pos){
        var anim = new ccs.Armature("b1all");
        anim.setScale(0.6);
        anim.animation.setSpeedScale(1);
        anim.setPosition(pos);
        this.addChild(anim);
        var that = this;
        anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
            cc.log("movementType:" + movementType);
            if (movementType == 1){
                armature.scheduleOnce(function(dt){
                    that.removeChild(armature);
                }, 5);
            }
        });

        anim.animation.play("baodan", 2, 0);
    },

    //赢了
    playWin : function(pos){
        var anim = new ccs.Armature("woyingle");
        anim.setScale(0.4);
        anim.animation.setSpeedScale(1);
        anim.setPosition(pos);
        this.addChild(anim);
        var that = this;
        anim.animation.setMovementEventCallFunc(function (armature, movementType, movementID) {
            cc.log("movementType:" + movementType);
            if (movementType == 1){
                armature.scheduleOnce(function(dt){
                    that.removeChild(armature);
                }, 0.5);
            }
        });

        anim.animation.play("woyingle-zong", 2, 0);
    }
});

